﻿#include "FITKVAOneXMLReader.h"
#include "FITKVAOneXMLIOInterface.h"
#include <rapidxml.hpp>
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaMaterial.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEASubSysAbsShell.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsTriangles.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscNodeList.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSEAModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEAFace.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEASubSysSemiInfiniteFluid.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsSpectraManager.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsMaterial.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsNCT.h"
#include "VAOneXMLAdaptorPhysicalProperty.h"
#include "VAOneXMLAdaptorSpectra.h"
#include "VAOneXMLAdaptorFrequencyDomain.h"
#include "VAOneXMLAdaptorNCT.h"
#include "VAOneXMLAdaptorMaterial.h"
#include "VAOneXMLAdaptorMaterialFE.h"
#include "VAOneXMLAdaptorNodes.h"
#include "VAOneXMLAdaptorSeaFacesPlate.h"
#include "VAOneXMLAdaptorSeaFacesSingleCurve.h"
#include "VAOneXMLAdaptorSeaFacesDoubleCurve.h"
#include "VAOneXMLAdaptorSeaPlateShell.h"
#include "VAOneXMLAdaptorSeaShellSingleCurve.h"
#include "VAOneXMLAdaptorSeaShellDoubleCurve.h"
#include "VAOneXMLAdaptorSeaBeam.h"
#include "VAOneXMLAdaptorSeaCavity.h"
#include "VAOneXMLAdaptorSinks.h"
#include "VAOneXMLAdaptorPowerSources.h"
#include "VAOneXMLAdaptorJunctions.h"
#include "VAOneXMLAdaptorConstraints.h"
#include "VAOneXMLAdaptorConnections.h"
#include "VAOneXMLAdaptorFESubSystems.h"
#include "VAOneXMLAdaptorAcousticFESubSystems.h"
#include "VAOneXMLAdaptorFESubSystemElementList.h"

namespace VAOne
{

    FITKVAOneXMLReader::FITKVAOneXMLReader(FITKVAOneXMLIOInterface* interface, bool & success)
        :_compInterface(interface), _isSuccess(success)
    {
        if (_compInterface == nullptr) return;
        _discModel = _compInterface->getDataObjectT<Acoustics::FITKAcousticsDiscModel>("Model");
        _physics = _compInterface->getDataObjectT<Acoustics::FITKAcousticsPhysics>("Physics");
    }

    FITKVAOneXMLReader::~FITKVAOneXMLReader()
    {

    }

    void FITKVAOneXMLReader::run()
    {
        if (_physics == nullptr || _discModel == nullptr) return;
        QString error;
        if (!this->createContent(error))
        {
            this->consoleMessage(3, error);
            return;
        }

        // to do 
        if (_document == nullptr) return;

        // clearManagerData();

        rapidxml::xml_node<>* modelNode = _document->first_node("Model");
        if (modelNode == nullptr) return;

        _isSuccess = true;
        // 部分节点不属于必然存在项，故未检索到的节点进行跳过

        // clearSeaModelData();

        // 进度条初始化
        updatePercent(Per_First);

        _isSuccess &= readModelSEAChildNodeData(modelNode);

        _isSuccess &= readModelFEChildNodeData(modelNode);

        // 连接
        if (nullptr != modelNode->first_node("Connections"))
        {
            IO::VAOneXMLAdaptorConnections* adaptorConnections = nullptr;
            _isSuccess &= adaptorRead<IO::VAOneXMLAdaptorConnections>("Connections", adaptorConnections, modelNode->first_node("Connections"));
        }
        updatePercent(Per_Connections);

        // 结束
        updatePercent(Per_Finish);

        if (!_isSuccess) consoleMessage(1, QObject::tr("%1 Import Fail.").arg(_fileName));
        consoleMessage(1, QObject::tr("%1 Import Success.").arg(_fileName));
    }

    void FITKVAOneXMLReader::updatePercent(VAOneXMLPercentType type)
    {
        int SpeedNumber = type * 100 / VAOneXMLPercentType::Per_Finish;
        sendCurrentPercent(SpeedNumber);
    }

    void FITKVAOneXMLReader::consoleMessage(int level, const QString& str)
    {
        switch (level)
        {
        case 1:AppFrame::FITKMessageNormal(str); break;
        case 2: AppFrame::FITKMessageWarning(str); break;
        case 3:AppFrame::FITKMessageError(str); break;
        default: AppFrame::FITKMessageError(str); break;
        }
    }

    void FITKVAOneXMLReader::clearSeaModelData()
    {
        // 获取sea模型数据
        Acoustics::FITKAcousticsSEAModel *model = _discModel->getSEAModel();
        if (nullptr == model) return;

        // 获取节点管理器
        Acoustics::FITKAcousticsDiscNodeList *dataManager = _discModel->getNodes();
        if (nullptr == dataManager) return;
        dataManager->removeAllNode();

        // 获取FACE管理器
        Acoustics::FITKSEAFaceManager *faceManager = model->getSEAFaceManager();
        if (nullptr == faceManager) return;
        faceManager->clear();

        // 获取数据管理器
        Acoustics::FITKAcousticsSEASubSysManager *subsystemManager = model->getSEASubSysManager();
        if (nullptr == subsystemManager) return;
        subsystemManager->clear();
    }

    void FITKVAOneXMLReader::clearManagerData()
    {
        if (!_physics) return;

        auto NCTManager = _physics->getFITKAcousticsNCTManager();
        if (NCTManager) NCTManager->clear();

        auto physicsPropManager = _physics->getPhysicsPropManager();
        if (physicsPropManager) physicsPropManager->clear();

        auto materialsManager = _physics->getMaterialManager();
        if (materialsManager) materialsManager->clear();

        auto spectraManager = _physics->getFITKAcousticsSpectraManager();
        if (spectraManager) spectraManager->clear();
    }

    bool FITKVAOneXMLReader::readModelSEAChildNodeData(rapidxml::xml_node<char>* node)
    {
        if (node == nullptr) return false;

        bool ok = true;

        // 频率
        if (nullptr != node->first_node("GlobalFrequencyDomain"))
            ok &= readrFrequencyDomain(node->first_node("GlobalFrequencyDomain"));
        updatePercent(Per_FrequencyDomain);

        // Nodes
        if (nullptr != node->first_node("Nodes"))
            ok &= readNodes(node->first_node("Nodes"));
        updatePercent(Per_Nodes);

        // 频谱
        if (nullptr != node->first_node("Spectra"))
            ok &= readSpectra(node->first_node("Spectra"));
        updatePercent(Per_Spectra);

        // 材料
        if (nullptr != node->first_node("Materials"))
            ok &= readMaterial(node->first_node("Materials"));
        updatePercent(Per_Materials);

        // FE材料
        if (nullptr != node->first_node("FEMaterials"))
            ok &= readMaterialFE(node->first_node("FEMaterials"));
        updatePercent(Per_FEMaterials);

        // 物理属性
        if (nullptr != node->first_node("PhysicalProperties"))
            ok &= readPhysicalProp(node->first_node("PhysicalProperties"));
        updatePercent(Per_PhysicalProperties);

        // 声包
        if (nullptr != node->first_node("NoiseControlTreatments"))
            ok &= readNCT(node->first_node("NoiseControlTreatments"));
        updatePercent(Per_NoiseControlTreatments);

        // 面
        if (nullptr != node->first_node("Faces"))
            ok &= readFaces(node->first_node("Faces"));
        updatePercent(Per_Faces);

        // 子系统
        if (nullptr != node->first_node("Subsystems"))
            ok &= readSubSystem(node->first_node("Subsystems"));
        updatePercent(Per_Subsystems);

        // 半无限流体
        if (nullptr != node->first_node("Sinks"))
        {
            IO::VAOneXMLAdaptorSinks* adaptorSinks = nullptr;
            ok &= adaptorRead<IO::VAOneXMLAdaptorSinks>("Sinks", adaptorSinks, node->first_node("Sinks"));
        }
        updatePercent(Per_Sinks);

        // 能量源
        if (nullptr != node->first_node("PowerSources"))
        {
            IO::VAOneXMLAdaptorPowerSources* adaptorPowerSources = nullptr;
            ok &= adaptorRead<IO::VAOneXMLAdaptorPowerSources>("PowerSources", adaptorPowerSources, node->first_node("PowerSources"));
        }
        updatePercent(Per_PowerSources);

        // 交点
        if (nullptr != node->first_node("Junctions"))
        {
            IO::VAOneXMLAdaptorJunctions* adaptorJunctions = nullptr;
            ok &= adaptorRead<IO::VAOneXMLAdaptorJunctions>("Junctions", adaptorJunctions, node->first_node("Junctions"));
        }
        updatePercent(Per_Junctions);

        // 约束
        if (nullptr != node->first_node("Constraints"))
        {
            IO::VAOneXMLAdaptorConstraints* adaptorConstraints = nullptr;
            ok &= adaptorRead<IO::VAOneXMLAdaptorConstraints>("Constraints", adaptorConstraints, node->first_node("Constraints"));
        }
        updatePercent(Per_Constraints);

        return ok;
    }

    bool FITKVAOneXMLReader::readModelFEChildNodeData(rapidxml::xml_node<char>* node)
    {
        if (node == nullptr) return false;

        bool ok = true;

        // 结构FE子系统
        if (nullptr != node->first_node("FESubsystems"))
        {
            IO::VAOneXMLAdaptorFESubSystems* adaptor = nullptr;
            ok &= adaptorRead<IO::VAOneXMLAdaptorFESubSystems>("FESubsystems", adaptor, node->first_node("FESubsystems"));
        }
        updatePercent(Per_FESubsystems);

        // 腔体FE子系统
        if (nullptr != node->first_node("AcousticFESubSystems"))
        {
            IO::VAOneXMLAdaptorAcousticFESubSystems* adaptor = nullptr;
            ok &= adaptorRead<IO::VAOneXMLAdaptorAcousticFESubSystems>("AcousticFESubSystems", adaptor, node->first_node("AcousticFESubSystems"));
        }
        updatePercent(Per_AcousticFESubSystems);

        // FE子系统单元列表
        for (rapidxml::xml_node<char>* child = node->first_node("FESubSystemElementList"); node != nullptr; child = child->next_sibling())
        {
            if (child == nullptr) break;

            IO::VAOneXMLAdaptorFESubSystemElementList* adaptor = nullptr;
            ok &= adaptorRead<IO::VAOneXMLAdaptorFESubSystemElementList>("FESubSystemElementList", adaptor, child);
        }
        updatePercent(Per_FESubSystemElementList);

        return ok;
    }

    bool FITKVAOneXMLReader::readNodes(rapidxml::xml_node<char> *node)
    {
        if (nullptr == node) return false;

        bool bOK = true;

        //获取sea模型数据
        Acoustics::FITKAcousticsSEAModel *model = _discModel->getSEAModel();
        if (nullptr == model) return false;

        //获取节点管理器
        Acoustics::FITKAcousticsDiscNodeList *dataManager = _discModel->getNodes();
        if (nullptr == dataManager) return false;

        //创建读取adaptor
        IO::VAOneXMLAdaptorNodes* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorNodes>("VAOneXML", dataManager);
        if (nullptr == adaptor) return false;

        //开始读取节点
        consoleMessage(1, tr("Start reading Nodes."));
        adaptor->setDataObject(dataManager);
        adaptor->setNode(node);
        bOK = adaptor->adaptR();
        if (true != bOK) consoleMessage(3, QString("Read Nodes Error"));

        delete adaptor;
        return bOK;
    }

#if 1
    bool FITKVAOneXMLReader::readFaces(rapidxml::xml_node<char> *node)
    {
        if (nullptr == node) return false;

        //获取sea模型数据
        Acoustics::FITKAcousticsSEAModel *model = _discModel->getSEAModel();
        if (nullptr == model) return false;

        //获取FACE管理器
        Acoustics::FITKSEAFaceManager *dataManager = model->getSEAFaceManager();
        if (nullptr == dataManager) return false;

        //开始读取FACE数据
        consoleMessage(1, tr("Start reading Faces."));

        bool bOK = true;

        bOK &= readFacePlate(node, dataManager);
        bOK &= readFaceSingleCurve(node, dataManager);
        bOK &= readFaceDoubleCurve(node, dataManager);

        return bOK;
    }
    bool FITKVAOneXMLReader::readFacePlate(rapidxml::xml_node<char>* node, Acoustics::FITKSEAFaceManager * manager)
    {
        if ((node == nullptr) || (manager == nullptr)) return false;

        //创建读取adaptor
        IO::VAOneXMLAdaptorSeaFacesPlate* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaFacesPlate>("VAOneXMLFacePlate", manager);
        if (nullptr == adaptor) return false;
        adaptor->setDataObject(manager);
        adaptor->setNode(node);

        bool ok = true;
        ok = adaptor->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read plate face Error"));
            delete adaptor;
            return false;
        }
        delete adaptor;
        return true;
    }
    bool FITKVAOneXMLReader::readFaceSingleCurve(rapidxml::xml_node<char>* node, Acoustics::FITKSEAFaceManager * manager)
    {
        if ((node == nullptr) || (manager == nullptr)) return false;

        //创建读取adaptor
        IO::VAOneXMLAdaptorSeaFacesSingleCurve* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaFacesSingleCurve>("VAOneXMLFaceSingleCurve", manager);
        if (nullptr == adaptor) return false;
        adaptor->setDataObject(manager);
        adaptor->setNode(node);

        bool ok = true;
        ok = adaptor->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read single curve Error"));
            delete adaptor;
            return false;
        }
        delete adaptor;
        return true;
    }
    bool FITKVAOneXMLReader::readFaceDoubleCurve(rapidxml::xml_node<char>* node, Acoustics::FITKSEAFaceManager * manager)
    {
        if ((node == nullptr) || (manager == nullptr)) return false;

        //创建读取adaptor
        IO::VAOneXMLAdaptorSeaFacesDoubleCurve* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaFacesDoubleCurve>("VAOneXMLFaceDoubleCurve", manager);
        if (nullptr == adaptor) return false;
        adaptor->setDataObject(manager);
        adaptor->setNode(node);

        bool ok = true;
        ok = adaptor->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read doubel curve Error"));
            delete adaptor;
            return false;
        }
        delete adaptor;
        return true;
    }
#endif // 读取面数据

#if 1
    bool FITKVAOneXMLReader::readSubSystem(rapidxml::xml_node<char> *node)
    {
        if (nullptr == node) return false;

        // 获取数据管理器
        Acoustics::FITKAcousticsSEAModel *model = _discModel->getSEAModel();
        if (nullptr == model) return false;
        Acoustics::FITKAcousticsSEASubSysManager *dataManager = model->getSEASubSysManager();
        if (nullptr == dataManager) return false;

        //开始读取子系统
        consoleMessage(1, tr("Start reading Subsystems."));

        bool bOK = true;

        bOK &= readSubSystemBeam(node, dataManager);
        bOK &= readSubSystemPlateShell(node, dataManager);
        bOK &= readSubSystemSingleCurveShell(node, dataManager);
        bOK &= readSubSystemDoubleCurveShell(node, dataManager);
        bOK &= readSubSystemCavity(node, dataManager);
        // 半无限流体没有子系统
        bOK &= readSubSystemSemiIInfiniteFluid(node, dataManager);

        //生成几何相关属性与SEA板三角形生成
        const int count = dataManager->getDataCount();
        for (int i = 0; i < count; ++i)
        {
            //子系统
            Acoustics::FITKAbstractSEASubSys* subsys = dataManager->getDataByIndex(i);
            if (!subsys) continue;
            //板数据
            Acoustics::FITKAbstractSEASubSysShell* shellData = dynamic_cast<Acoustics::FITKAbstractSEASubSysShell*>(subsys);
            if (!shellData)
            {
                //不是板只算几何属性
                subsys->updateGeoProp();
                continue;
            }
            //板里没有三角形，生成新的三角形，并计算几何属性
            Acoustics::FITKAcousticsTriangles* mesh = shellData->getTriangleMesh();
            if (!mesh)continue;
            if (mesh->getElementCount() == 0) shellData->updateTriMesh();
            shellData->updateGeoProp();
        }
        return bOK;
    }

    bool FITKVAOneXMLReader::readSubSystemBeam(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager * manager)
    {
        if ((node == nullptr) || (manager == nullptr)) return false;

        //创建adaptor
        IO::VAOneXMLAdaptorSeaBeam* adaptorBeam = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaBeam>("VAOneXMLBeam", manager);
        if (nullptr == adaptorBeam)  return false;
        adaptorBeam->setDataObject(manager);
        adaptorBeam->setNode(node);

        bool ok = true;
        ok = adaptorBeam->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read sub system beam Error"));
            delete adaptorBeam;
            return false;
        }
        delete adaptorBeam;
        return true;
    }

    bool FITKVAOneXMLReader::readSubSystemPlateShell(rapidxml::xml_node<char> *node, Acoustics::FITKAcousticsSEASubSysManager *manager)
    {
        if ((nullptr == node) || (nullptr == manager)) return false;

        //创建adaptor
        IO::VAOneXMLAdaptorSeaPlateShell* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaPlateShell>("VAOneXMLPlateShell", manager);
        if (nullptr == adaptor) return false;
        adaptor->setDataObject(manager);
        adaptor->setNode(node);

        bool ok = true;
        ok = adaptor->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read sub system plate shell Error"));
            delete adaptor;
            return false;
        }
        delete adaptor;
        return true;
    }
    bool FITKVAOneXMLReader::readSubSystemSingleCurveShell(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager * manager)
    {
        if ((nullptr == node) || (nullptr == manager)) return false;

        //创建adaptor
        IO::VAOneXMLAdaptorSeaShellSingleCurve* adaptorS = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaShellSingleCurve>("VAOneXMLSingleCurveShell", manager);
        if (nullptr == adaptorS) return false;
        adaptorS->setDataObject(manager);
        adaptorS->setNode(node);

        bool ok = true;
        ok = adaptorS->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read sub system single curve shell Error"));
            delete adaptorS;
            return false;
        }

        delete adaptorS;
        return true;
    }
    bool FITKVAOneXMLReader::readSubSystemDoubleCurveShell(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager * manager)
    {
        if ((nullptr == node) || (nullptr == manager)) return false;

        //创建adaptor
        IO::VAOneXMLAdaptorSeaShellDoubleCurve* adaptorD = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaShellDoubleCurve>("VAOneXMLDoubleCurveShell", manager);
        if (nullptr == adaptorD) return false;
        adaptorD->setDataObject(manager);
        adaptorD->setNode(node);

        bool ok = true;
        ok = adaptorD->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read sub system double curve shell Error"));
            delete adaptorD;
            return false;
        }
        delete adaptorD;
        return true;
    }
    bool FITKVAOneXMLReader::readSubSystemCavity(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager * manager)
    {
        if ((nullptr == node) || (nullptr == manager)) return false;

        //创建adaptor
        IO::VAOneXMLAdaptorSeaCavity* adaptorCavity = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSeaCavity>("VAOneXMLCavity", manager);
        if (nullptr == adaptorCavity) return false;
        adaptorCavity->setDataObject(manager);
        adaptorCavity->setNode(node);

        bool ok = true;
        ok = adaptorCavity->adaptR();
        if (true != ok)
        {
            consoleMessage(3, QString("Read sub system cavity Error"));
            delete adaptorCavity;
            return false;
        }
        delete adaptorCavity;
        return true;
    }
    bool FITKVAOneXMLReader::readSubSystemSemiIInfiniteFluid(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager * manager)
    {
        //if ((nullptr == node) || (nullptr == manager)) return false;
        return true;
    }
#endif // 读取子系统数据

    bool FITKVAOneXMLReader::readMaterial(rapidxml::xml_node<char>* node)
    {
        Acoustics::FITKAcousticsMaterialManager* m = _physics->getMaterialManager();
        if (!m) return false;
        IO::VAOneXMLAdaptorMaterial* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorMaterial>("VAOneXML", m);
        if (!adaptor) return false;
        //开始读取材料
        consoleMessage(1, tr("Start reading Materials."));
        adaptor->setDataObject(m);
        adaptor->setNode(node);
        bool R = adaptor->adaptR();
        if (!R)
        {
            consoleMessage(3, QString("Read Material Error"));
            //delete dataCase;
        }
        delete adaptor;
        return R;
    }

    bool FITKVAOneXMLReader::readMaterialFE(rapidxml::xml_node<char> *node)
    {
        Acoustics::FITKAcousticsFEModel* feModel = _discModel->getFEModel();
        if (!feModel) return false;
        Interface::FITKMaterialManager* manager = feModel->getMaterialManager();
        if (!manager) return false;

        bool b = true;
        IO::VAOneXMLAdaptorMaterialFE* adaptor{};
        rapidxml::xml_node<char>* materialFENode = node->first_node("FEMaterial");

        while (nullptr != materialFENode)
        {
            Interface::FITKAbaMaterial*  materialPtr = new Interface::FITKAbaMaterial();
            if (nullptr == adaptor)
            {
                adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorMaterialFE>("VAOneXML", materialPtr);
                if (nullptr == adaptor) return false;
            }

            consoleMessage(1, tr("Start reading FEMaterial."));
            adaptor->setDataObject(materialPtr);
            adaptor->setNode(materialFENode);

            bool R = adaptor->adaptR();
            if (!R) consoleMessage(3, QString("Read FEMaterial Error"));

            //根据名称获取对象
            auto m = manager->getDataByName(materialPtr->getDataObjectName());
            if (!m)
            {
                //返回为空 插入mData
                manager->appendDataObj(materialPtr);
            }
            else
            {
                //返回不为空， 覆盖数据
                m->copy(materialPtr);
                delete materialPtr;
            }
            materialFENode = materialFENode->next_sibling("FEMaterial");
        }

        if (adaptor)
        {
            delete adaptor;
            adaptor = nullptr;
        }
        return b;
    }

    bool FITKVAOneXMLReader::readPhysicalProp(rapidxml::xml_node<char>* node)
    {
        IO::VAOneXMLAdaptorPhysicalProperty* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorPhysicalProperty>("VAOneXML", _physics->getPhysicsPropManager());
        if (!adaptor) return false;
        //开始读取材料
        consoleMessage(1, tr("Start reading PhysicalProperties."));
        adaptor->setDataObject(_physics->getPhysicsPropManager());
        adaptor->setNode(node); //physicalPropNode

        bool R = adaptor->adaptR();
        if (!R) consoleMessage(3, QString("Read Physical Error"));

        delete adaptor;
        return R;
    }

    bool FITKVAOneXMLReader::readSpectra(rapidxml::xml_node<char> *node)
    {
        if (nullptr == node) return false;

        Acoustics::FITKAcousticsSpectraManager* s = _physics->getFITKAcousticsSpectraManager();
        if (!s) return false;
        IO::VAOneXMLAdaptorSpectra* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorSpectra>("VAOneXML", s);
        if (!adaptor) return false;
        //开始读取频谱
        consoleMessage(1, tr("Start reading Spectra."));
        adaptor->setDataObject(s);
        adaptor->setNode(node);
        bool R = adaptor->adaptR();
        if (!R) consoleMessage(3, QString("Read Spectra Error"));

        delete adaptor;
        return R;
    }

    bool FITKVAOneXMLReader::readrFrequencyDomain(rapidxml::xml_node<char> *node)
    {
        if (nullptr == node) return false;  //frequencyDomainNode

        Acoustics::FITKGlobalFrequencyDomain* f = _physics->getFrequencyDomain();
        if (!f) return false;
        IO::VAOneXMLAdaptorFrequencyDomain* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorFrequencyDomain>("VAOneXML", f);
        if (!adaptor) return false;
        //开始读取频率
        consoleMessage(1, tr("Start reading GlobalFrequencyDomain."));
        adaptor->setDataObject(f);
        adaptor->setNode(node);
        bool R = adaptor->adaptR();
        if (!R) consoleMessage(3, QString("Read GlobalFrequencyDomain Error"));

        delete adaptor;
        return R;
    }

    bool FITKVAOneXMLReader::readNCT(rapidxml::xml_node<char> *node)
    {
        Acoustics::FITKAcousticsNCTManager* manager = _physics->getFITKAcousticsNCTManager();
        if (!manager) return false;

        IO::VAOneXMLAdaptorNCT* adaptor = FITKIOADAPTORFACTORY->createT<IO::VAOneXMLAdaptorNCT>("VAOneXML", manager);
        if (!adaptor) return false;

        //开始读取声包
        consoleMessage(1, tr("Start reading NoiseControlTreatments."));
        adaptor->setDataObject(manager);
        adaptor->setNode(node);
        bool R = adaptor->adaptR();
        if (!R) consoleMessage(3, QString("Read NCT Error"));
        delete adaptor;
        return R;
    }
}


